from scapy.all import *
from scapy.layers.l2 import Ether
from scapy.layers.inet import IP, UDP
from scapy.fields import ByteField


class SourceRouting(Packet):
    name="SourceRouting"
    fields_desc = [
        ByteField("current_index", 0),
        ByteField("path_len", 2),
        ByteField("port0", 4),
        ByteField("port1", 2),
        ByteField("port2", 0),
        ByteField("port3", 0)
    ]
bind_layers(Ether, SourceRouting, type=0x1234)


def send_source_routing_packet():
    pkt = (
        Ether(dst="FF:FF:FF:FF:FF:FF", src="08:00:00:00:01:11") /
        SourceRouting() /
        IP(dst="10.0.2.2") /
        UDP(dport=1234, sport=5678)
        )

    sendp(
        pkt,
        iface="eth0",
        verbose=True,
        loop=30,
        inter=1
    )

if __name__ == '__main__':
    send_source_routing_packet()
